package com.example.administrator.maizuofilm.moviedetails.moviecomment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.administrator.maizuofilm.BaseActivity;
import com.example.administrator.maizuofilm.R;
import com.example.administrator.maizuofilm.moviedetails.bean.DetailsComment;
import com.example.administrator.maizuofilm.moviedetails.moviedetailsadapter.DetailsCommentAdapter;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by hansen on 2016/7/14.
 */
public class MoviesCommentActivity extends BaseActivity implements MoviesCommentContract.commentView {
    @InjectView(R.id.comm_userPci)
    ImageView commUserPci;
    @InjectView(R.id.comm_userName)
    TextView commUserName;
    @InjectView(R.id.comm_com)
    TextView commCom;
    @InjectView(R.id.comm_time)
    TextView commTime;
    @InjectView(R.id.comm_goodPic)
    ImageView commGoodPic;
    @InjectView(R.id.comm_goodNum)
    TextView commGoodNum;
    @InjectView(R.id.comm_commPic)
    ImageView commCommPic;
    @InjectView(R.id.comm_commendNum)
    TextView commCommendNum;
    @InjectView(R.id.commend_recylerview)
    RecyclerView commendRecylerview;
    @InjectView(R.id.commend_toolbar)
    Toolbar commendToolbar;
    @InjectView(R.id.commend_back)
    ImageView commendBack;

    private MoviesCommentContract.commenModel model;
    private MoviesCommentContract.commentPresenter presenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_movidecomment);
        ButterKnife.inject(this);

        setSupportActionBar(commendToolbar);

        model=new MoviesCommentModel();
        presenter=new MoviesCommentPresenter(this,model);

//获得评论 并获得该评论reviewid
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        String reviewId = bundle.getString("reviewId");
        String username = bundle.getString("username");
        String commend = bundle.getString("commend");
        String commenduserPci = bundle.getString("commenduserPci");
        String commendtime = bundle.getString("commendtime");
        String commend_commendNum = bundle.getString("commend_commendNum");
        String commend_goodNum = bundle.getString("commend_goodNum");

        //给本来的评论赋值
        commUserName.setText(username);
        Glide.with(this).load(commenduserPci).error(R.drawable.iv_comments_icon).into(commUserPci);
        commCom.setText(commend);
        commTime.setText(commendtime);
        commCommendNum.setText(commend_commendNum);
        commGoodNum.setText(commend_goodNum);

        //调用present
        FullyLinearLayoutManager manager=new FullyLinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        commendRecylerview.setLayoutManager(manager);

        presenter.getDetailsComment(reviewId);

    }

//activity 自杀
    @OnClick(R.id.commend_back)
    public void onClick() {
        this.finish();
    }

    @Override
    public void onDetailsComment(DetailsComment comm) {
        Log.i("tag","--------->"+comm.getData().get(0).getAuthorName());
        DetailsCommentAdapter adapter=new DetailsCommentAdapter(getApplicationContext(),comm.getData());
        commendRecylerview.setAdapter(adapter);

    }

    @Override
    public void onFail(String str) {
        Toast.makeText(this,str,Toast.LENGTH_SHORT).show();;
    }
}
